package zhaoyong.wang.tlias.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import zhaoyong.wang.tlias.pojo.Emp;
import zhaoyong.wang.tlias.pojo.PageBean;
import zhaoyong.wang.tlias.pojo.Result;
import zhaoyong.wang.tlias.service.impl.EmpService;
import zhaoyong.wang.tlias.service.impl.EmpServicelmpl;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
        @Autowired
        private EmpServicelmpl empServicelmpl;
        @GetMapping
    public Result Page(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                         String name, Short gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){
            log.info("分页查询");
            PageBean emps = empServicelmpl.page(page,pageSize,name,gender,begin,end);
            return Result.success(emps);
            //name,gender,begin,end

        }
        @DeleteMapping("/{ids}")
        public Result delet(@PathVariable List<Integer> ids){
            log.info("删除员工操作");
            empServicelmpl.delete(ids);
            return Result.success();
        }
        @PostMapping
        public Result insert(@RequestBody Emp emp){
            log.info("增加员工操作");
            empServicelmpl.insert(emp);
            return Result.success();
        }
        @GetMapping("/{id}")
        public Result getByid(@PathVariable Integer id){
            Emp emp = empServicelmpl.getByid(id);
            return Result.success(emp);
        }
        @PutMapping
        public Result update(@RequestBody Emp emp){
            log.info("更新员工");
            empServicelmpl.update(emp);
            return Result.success();
        }
}
